<?php
/**
 * Yii bootstrap file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

require(__DIR__ . '/BaseYii.php');

/**
 * Yii is a helper class serving common framework functionalities.
 *
 * It extends from [[\yii\BaseYii]] which provides the actual implementation.
 * By writing your own Yii class, you can customize some functionalities of [[\yii\BaseYii]].
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class Yii extends \yii\BaseYii
{
    static public function baselog($file, $msg, $is_append = false)
    {
        if ($is_append)
            file_put_contents($file, $msg, FILE_APPEND);
        else
            file_put_contents($file, $msg);
    }

    static public function log($tag, $msg = '', $location = '', $dir = '.')
    {
        static $is_dirty = false;
        $tag = print_r($tag, true);
        $dir .= '/logs';
        is_dir($dir) || @mkdir($dir, 0777, true);
        $msg = print_r($msg, true);
        $log_file = $dir . date('y-m-d H', time()) . '.log';
        if (!$is_dirty) {
            self::baselog($log_file, '');
            $is_dirty = true;
        }
        self::baselog($log_file, '[' . date('Y-m-d H:i:s', time()) . '][' . $tag . '] VAR[' . $msg . '] [' . $location . ']' . str_repeat(PHP_EOL, 2), true);
    }

    static public function record_trace($tag = 'tag', $dir = '.')
    {
        $tag = print_r($tag, true);
        $dir .= '/logs';
        is_dir($dir) || @mkdir($dir, 0777, true);
        $trace = debug_backtrace();
        self::baselog($tag . '.backtrace', print_r($trace, true));
    }
}

spl_autoload_register(['Yii', 'autoload'], true, true);
Yii::$classMap = require(__DIR__ . '/classes.php');
Yii::$container = new yii\di\Container();
